package com.cyzy.controller;

import com.cyzy.dto.AdoptDetailDto;
import com.cyzy.dto.AdoptListDto;
import com.cyzy.dto.Result;
import com.cyzy.pojo.Protocol;
import com.cyzy.service.AdoptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 认养接口
 */
@RestController
@RequestMapping("/adopt")
public class AdoptController {
    
    @Autowired
    private AdoptService adoptService;

    /**
     * 获取认养列表
     * @return 认养列表
     */
    @GetMapping("/list")
    public Result getAdoptList() {
        List<AdoptListDto> adoptList = adoptService.getAdoptList();
        return Result.ok().data("adoptList", adoptList);
    }
    
    /**
     * 获取认养协议内容
     * @return 协议内容
     */
    @GetMapping("/protocol")
    public Result getAdoptProtocol() {
        Protocol protocol = adoptService.getAdoptProtocol();
        if (protocol != null) {
            return Result.ok().data("protocol", protocol);
        } else {
            return Result.error().message("未找到有效的认养协议");
        }
    }
    
    /**
     * 根据ID获取认养详情
     * @param adoptId 认养ID
     * @return 认养详情
     */
    @GetMapping("/detail/{adoptId}")
    public Result getAdoptDetail(@PathVariable("adoptId") Long adoptId) {
        AdoptDetailDto adoptDetail = adoptService.getAdoptDetail(adoptId);
        if (adoptDetail != null) {
            return Result.ok().data("adoptDetail", adoptDetail);
        } else {
            return Result.error().message("未找到该认养项目或项目已下架");
        }
    }

} 